
<template>
  <div>
    <van-field v-model="searchTxt" center clearable label="地址:" placeholder="请输入关键词" >
      <van-button slot="button" size="small" type="primary" @click="getLists">查询</van-button>
    </van-field>      

      <van-swipe-cell v-for="(i,index) in items" :key="index">
        <van-panel :title="i.Dicts.name+'-'+i.hope_addr" :status="i.checked?'已核实':'未核实'">
          <p>
            {{i.date_begin}},有{{i.checkin_num}}名{{i.conn_type}}人员,
              电话:{{i.conn_phone}}-{{i.conn_person}},{{i.remark}}
              <span v-show="i.hotel_id>0">【已申请:{{i.Wh_hotel?i.Wh_hotel.name:''}}】</span>
          </p>
          <div slot="footer">
                <van-button size="mini">查看详情</van-button>
                <van-button size="mini" type="primary" @click="orderIt(i)">接单</van-button>
                <van-button size="mini" type="primary" @click="orderIt(i)">拒绝</van-button>
          </div>
        </van-panel>
      </van-swipe-cell>

  </div>
</template>

<script>
  import { get } from "@/api/common";
  import { Toast,Dialog } from 'vant';

  export default {
    components: {
    },
    data() {
      return {
        checkeds: [],
        searchTxt: '',
        areaValue: 0,
        hospital: {},
        items: [],
      }
    },
    mounted() {
      this.getLists();
    },
    methods: {
      orderIt(item) {
        let msg = '请确定是否具备接待能力：\n'+
                  '\n入住人数：'+item.checkin_num+
                  '\n入住开始日期：'+item.date_begin+
                  '\n入住结束日期：'+item.date_end;
        Dialog.confirm({
          title: '我来接单',
          message: msg
        }).then(() => {
          Toast('假的，还没实现')
        }).catch(() => {
          // on cancel
        });
      },
      // 调用api获得当前选择的申请列表
      getLists(){
        let body = {
                  '@column': 'id,hope_addr,conn_person,conn_phone,checkin_num,checked,checkin_area,call_user_id,volu_user_id,hotel_id,date_begin,date_end',
                  '@order': 'date_begin-',
                  };
        if(this.areaValue>0)
          body['hotel_id'] = [1,2,3,4,5,6];
        let params = {'[]': {
                'Wh_checkin_apply': body,
                'Dicts':{
                  '@column': 'value,name',
                  'value@': '/Wh_checkin_apply/checkin_area',
                  'object': 'wh_hotel',
                  'field': 'checkin_area'
                },
                'Wh_hotel': {
                  '@column': 'id,name',
                  'id@': '/Wh_checkin_apply/hotel_id',
                },
                'count':2,
              }
            };
        get(params)
          .then( res=> {
            if(res.data.code==200){
              this.items = [];
              var data = res.data["[]"];
              for(var d in data) {
                var a = data[d].Wh_checkin_apply;
                var h = data[d].Wh_hotel;
                var d = data[d].Dicts;
                a['Wh_hotel'] = h==undefined?{}:h;
                a['Dicts'] = d==undefined?{}:d;
                this.items.push(a);
              }
            }
            else
              Toast('读取申请记录失败'); 
            })
          .catch(function (error){
              console.log(error);
          });
      },
    }
  }
</script>

<style scoped>
p{
  padding-left:10px;
}
</style>
  